<extend name="Public/base" />

<block name="body">
	<style>
		.importArea{
		    padding: 10px;
    padding-top: 20px;
    border-radius: 10px;
    border: 1px solid #D9D7D7;
    margin-top: 20px;
		}
		
		.importArea textarea {
			    margin-top: 20px;
    width: 100%;
    height: 450px; display: none;
		}
	</style>
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>用户列表</h2>
	</div>
	<div class="" style="display: block;">
	<form name="scanfrm" class="search-form" action="{:U('studen/index')}" method="post">
                	<div class="row">
                		<label>注册时间：</label>
                		<input type="text" id="time-start" name="time-start" class="text input-2x" value="" placeholder="起始时间"> -
                		<input type="text" id="time-end" name="time-end" class="text input-2x" value="" placeholder="结束时间">
                		<label>学生姓名：</label>
						<input type="text"   name="fullname" id="fullname" class="text input-2x" value=""  />
						<label>手机号：</label>
						<input type="text"   name="telephone" id="telephone" class="text input-2x" value=""  />
                	 	
                	 	<if condition="IS_ROOT != false">
                			<label>类型：</label>		 
	                		{$query_select_role_member}
	                		</select>
                		</if>
                </div>
                <div class="row">
						 
                			<label>活动类型：</label>	
                			<select name="active_type" class="active_type">
                				<option value="">全部</option>
                				<foreach name="select_active_type" item="item" key="key">
									<option value="{$key}">{$item}</option>
                				</foreach>
                			</select>	 
                		 
						
						 
                			<label>UID：</label>	
                			<input type="text" name="id" id="id" class="text input-2x" value=""  /> 
                		 
						
						 
                			<label>意外值：</label>	
                			<select name="intention" class="intention">
                				<option value=""></option>
                				<option value="0">0</option>
                				<option value="1">1</option>
                				<option value="2">2</option>
                				<option value="3">3</option>
                				<option value="4">4</option>
                				<option value="5">5</option>
                				 
                			</select>	 
                		 
                			<label>是否回访：</label>	
                			<select name="accesslog" class="accesslog">
                				
                				<option value=""></option>
                				<option value="1">是</option>
                				<option value="0">否</option>
                			 
                			</select>	 
                		 	
                		 	<label>是否有效：</label>	
                			<select name="is_effective" class="is_effective">
                				<option value=""></option>
                				<option value="1">是</option>
                				<option value="0">否</option>
                			</select>	 
                	</div>

        <div class="row">
            <input type="submit" class="sch-btn" value="查 询" />
            &nbsp;&nbsp;&nbsp;<input type="button" class="sch-btn reset-btn" value="重置信息"  />
			&nbsp;&nbsp;&nbsp;
			<input type="button" class="sch-btn import-btn" value="导入"  />
			&nbsp;&nbsp;&nbsp;
			<input type="button" class="sch-btn" value="刷新" onclick="javascript:location.reload();"  />
        </div>
        </form>
    </div>

	<div class="cf infoArea" style="padding-top: 20px;">
		<div class="fl">
            <a class="btn" href="{:U('admin/studen/editview')}">新 增</a>
           <!--  <button class="btn ajax-post" url="{:U('admin/changeStatus',array('method'=>'resumeUser'))}" target-form="ids">启 用</button>
            <button class="btn ajax-post" url="{:U('User/changeStatus',array('method'=>'forbidUser'))}" target-form="ids">禁 用</button> -->
            <if condition="IS_ROOT != false">
            <button class="btn   confirm action-deleuser" url="{:U('admin/studen/deleteUser')}" target-form="ids">删 除</button>
            </if>
        </div>

        
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped infoArea">
	<table class="">
    <thead>
        <tr>
		<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
		<th class="">UID</th>
		<th class="">姓名</th>
		<th class="">所在学校</th>
		<th class="">年龄</th>
		<th class="">联系电话</th>
		<th class="">注册时间</th>
		<th class="">回访</th>
		 
			<th class="">来源</th>
			<if condition="false"> 
				//说明：顾问角色21就可以将内部人员那列去掉
			</if> 
		<if condition="!in_array($myRole,array(21))"> 

			<th class="">内部人员</th>
		</if>
		
		<th class="">状态</th>
		<th class="">操作</th>
		</tr>
    </thead>
    <tbody>

    <form method="post" id="thefrm">
		<volist name="_list" id="vo">
		<tr>
            <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
			<td>{$vo.id} </td>
			<td>{$vo.fullname}</td>
			<td>{$vo.school}</td>
			<td>{$vo.generation_name}</td>
			<td><span>{$vo.telephone}</span></td>
			<td><span>{$vo.registered_time|date="Y-m-d H:i",###}</span></td>	 		 
			<td><span>{$vo.access_info}</span></td>	
			 
			<td>
				<foreach name="vo.bindList" item="vo2" >
					<?php if (substr($key, 0, 1 )==1) { ?>
					<span class="bind bind{$key}">
									<if condition="$key eq 11">地推</if>
										<if condition="$key eq 12">商户</if>
										<if condition="$key eq 13">客户经理</if>
										 
					*{$vo2.nickname}</span>	
					<?php } ?>
				</foreach>	
			</td> 	
			 
			<if condition="!in_array($myRole,array(21))"> 
			<td>
				<foreach name="vo.bindList" item="vo2" >
					<?php if (substr($key, 0, 1 )==2) { ?>
					<span class="bind bind{$key}">
							<if condition="$key eq 21">课程顾问</if>
							<if condition="$key eq 22">老师</if>
							<if condition="$key eq 23">助理</if>
							<if condition="$key eq 24">教务</if>
							<if condition="$key eq 25">市场</if>			 
					*{$vo2.nickname}</span>	
					<?php } ?>
				</foreach>	
			</td> 
			</if>
			<td><if condition="$vo.is_effective eq 1">有效<else/>无效</if></td>
			<td><if condition="$vo.is_effective eq 1">
				<a href="{:U('Admin/studen?method=changeStatus&status=0&id='.$vo['id'])}" class="ajax-get">无效</a>
				<else/>
				<a href="{:U('Admin/studen?method=changeStatus&status=1&id='.$vo['id'])}" class="ajax-get">有效</a>
				</if>
				<!-- <a href="{:U('AuthManager/group?uid='.$vo['uid'])}" class="confirm ajax-get">删除</a> -->
				<a href="{:U('Admin/studen/editview',array('id'=>$vo['id']) )}"  >编辑</a>
             </td>
		</tr>
		</volist>
	 </form>
	</tbody>
    </table> 
	</div>
    <div class="page infoArea">
        {$_page}
    </div>
        <if condition="!$_list" >
        <div class="infoArea" style="text-align: center; border: 1px solid #AEACAC; border-radius: 5px; height: 40px; padding-top: 20px;">无符合条件的数据!</div>
        </if>
	<Div class="importArea" style="display:none">
	<table style="width:100%;">
		<form id="improtFrm" method="post" action="/index.php?s=/admin/studen/doImport.html" enctype="multipart/form-data" >  
		<tr>
			<td class="import-row">
				
				<input type="file" name="upfile" id="upfile"/>(只能导入csv文件)
				<button type="submit">确定</button>
				<em style="display:none"> </em>
				<textarea style=""><?php echo session('improt_info')?></textarea>
			</td>
		</tr>
 		</form>	
		
	</table>
	</div>
	
 

</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
<link href="/Public/static/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<link href="/Public/static/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css"><link href="/Public/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/Public/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/Public/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

<script type="text/javascript" src="/Public/static/ajaxfileupload.js" charset="UTF-8"></script>
<script type="text/javascript">

	/*
	设定选择值
	*/
	$(".queryRole").val('{$Think.post.queryRole}'); 
	$(".active_type").val('{$Think.post.active_type}'); 
	$("#time-start").val('{$Think.post.time-start}');
	$("#time-end").val('{$Think.post.time-end}');
	$("#fullname").val('{$Think.post.fullname}');
	$("#telephone").val('{$Think.post.telephone}');

	$("#id").val('{$Think.post.id}');
	$(".intention").val('{$Think.post.intention}');
	$(".accesslog").val('{$Think.post.accesslog}');
	$(".is_effective").val('{$Think.post.is_effective}');
 
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    //导航高亮
    $('.side-sub-menu').find('a[href="{:U('User/index')}"]').closest('li').addClass('current');

    /* 状态搜索子菜单 */
	$(".search-form").find(".drop-down").hover(function(){
		$("#sub-sch-menu").removeClass("hidden");
	},function(){
		$("#sub-sch-menu").addClass("hidden");
	});

	$("#sub-sch-menu li").find("a").each(function(){
		$(this).click(function(){
			var text = $(this).text();
			$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
			$("#sub-sch-menu").addClass("hidden");
		})
	});

	$(document).on("click","#search",function(){
		_self = this;
		
	})

	//删除用户
	$(document).on("click",".action-deleuser",function(){
		_self = this;
		_url = $(_self).attr("url");

		_data =$("#thefrm").serialize();
 	
		if (!_data) {
			alert("未选择记录");
			return false;
		}

		$.post(_url,_data,function(res){
			_o = eval("("+res+")");
			if (_o.status=="success") {
				//刷新自己
				//$('.message').modal('toggle');
				
				location.reload() ;
				return false;
			} else {
				if (_o.msg) {
					alert(_o.msg);
					return false;
				}
			}
		})
	})

	$('#time-start').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });

    $('#time-end').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });

     $(".reset-btn").on("click",function(){
            $('input[type=text]').val('');
            $('select').val('');

        })

	$(".import-btn").on("click",function(){
		$(".infoArea").hide();
		$(".importArea").show();
	})
	
	<if condition="$import">
		$(".infoArea").hide();
		$(".importArea").show();

		$(".import-row textarea").show();

		//.import-row textarea
	</if>

	$("button[type='submit']").on("click",function(){
 
		    _em = $(".import-row").find("em");
			_em.hide();
			var t=  $("input[type='file']").val();
			  reg=/([^\s]+(?=\.(csv))\.\2)/gi;
			  if(!reg.test(t))
			  {
				_em.html("文件名类型不对,不能上传");
				_em.show();
				return false;  
			  }  else {
					$("#improtFrm").submit();
				}	
			/*	
			_data = $("#improtFrm").serializeObject();
			$.ajaxFileUpload({ 
				type: "POST",
				secureuri:false,
				url:  "/index.php?s=/admin/studen/doImport.html",
				fileElementId:['upfile'],
				data: _data ,
				dataType: 'json' ,
				success : function(data) {  
					debugger;
				} 

			}); 
 
 */
			 
			return false; 
        })
	</script>
	
</block>
